/**
 * 角色接口
 */

const Router = require("koa-router");
const router = new Router();
const { SystemRoleController } = require("../controller/sys_role.js");
const passport = require("koa-passport");
const auth = require("../middleware/auth.js");
const dataScope = require("../middleware/dataScope.js");
const { SystemDeptController } = require("../controller/sys_dept.js");

// 获取所有的权限 根据dataScope 判断
router.get(
  "/v1/system/role/list",
  passport.authenticate("jwt", { session: false }),
  auth("system:role:query"),
  dataScope,
  SystemRoleController.sysRoleList
);
// 新增角色
router.post(
  "/v1/system/role/add",
  passport.authenticate("jwt", { session: false }),
  auth("system:role:add"),
  SystemRoleController.sysRoleAdd
);
// 更新角色
router.post(
  "/v1/system/role/update",
  passport.authenticate("jwt", { session: false }),
  auth("system:role:edit"),
  SystemRoleController.sysRoleUpd
);
// 查询数据权限 dataScope 数据范围（1：全部数据权限 2：自定数据权限 3：本部门数据权限 4：本部门及以下数据权限 5.仅本人数据权限）
router.post(
  "/v1/system/role/dateScope",
  passport.authenticate("jwt", { session: false }),
  auth("system:role:edit"),
  SystemRoleController.sysRoleDataScope
);
// 删除
router.post(
  "/v1/system/role/delete",
  passport.authenticate("jwt", { session: false }),
  auth("system:role:remove"),
  SystemRoleController.sysRoleDel
);
// 批量删除
router.post(
  "/v1/system/role/deleteByIds",
  passport.authenticate("jwt", { session: false }),
  auth("system:role:remove"),
  SystemRoleController.sysRoleDelByIds
);

// @@@ 测试5

// 获取授权用户 查询条件用户名称/手机号码
router.post(
  "/v1/system/role/authUser/allocatedList",
  passport.authenticate("jwt", { session: false }),
  auth("system:role:query"),
  SystemRoleController.allocatedList
);

// 获取未授权用户 datascope 获取 查询条件用户名称/手机号码
router.post(
  "/v1/system/role/authUser/unallocatedList",
  passport.authenticate("jwt", { session: false }),
  auth("system:role:query"),
  SystemRoleController.unallocatedList
);

// 添加授权用户
router.post(
  "/v1/system/role/authUser/batchAddUser",
  passport.authenticate("jwt", { session: false }),
  auth("system:role:add"),
  SystemRoleController.batchAddUser
);

// 取消授权用户
router.post(
  "/v1/system/role/authUser/cancelUser",
  passport.authenticate("jwt", { session: false }),
  auth("system:role:cencelUser"),
  SystemRoleController.cancelAuthUser
);

// 批量取消用户
router.post(
  "/v1/system/role/authUser/batchCancelUser",
  passport.authenticate("jwt", { session: false }),
  auth("system:role:cencelUser"),
  SystemRoleController.batchCancelUser
);

// 根据id获取信息-
router.post(
  "/v1/system/role/getById",
  passport.authenticate("jwt", { session: false }),
  auth("system:role:query"),
  SystemRoleController.sysRoleById
);

// 修改状态
router.post(
  "/v1/system/role/changeStatus",
  passport.authenticate("jwt", { session: false }),
  auth("system:role:edit"),
  SystemRoleController.changeStatus
);

// 导出
router.post(
  "/v1/system/role/export",
  passport.authenticate("jwt", { session: false }),
  auth("system:role:export"),
  SystemRoleController.sysRoleExport
);

// 通过role_id获取菜单
router.post(
  "/v1/system/role/deptTree",
  passport.authenticate("jwt", { session: false }),
  auth("system:menu:query"),
  SystemDeptController.roleDeptTreeselect
);
module.exports = router;
